This notebook explores the relationship between the soundscape power and contributing land cover area for sounds in a pumilio database.
In [1]:
import pandas
from Pymilio import database
import numpy as np
from colour import Color
In [2]:
import matplotlib.pylab as plt
In [3]:
%matplotlib inline
In [4]:
db = database.Pymilio_db_connection(user='pumilio',
database='pumilio',
read_default_file='~/.my.cnf.pumilio')
In [5]:
Sounds = db.fetch_as_pandas_df(table='Sounds', fields=['SoundID', 'SiteID', 'ColID']).set_index('SoundID')
Sites = db.fetch_as_pandas_df(table='Sites',
fields=['SiteID', 'ID', 'SiteName'],
where='ID > 0 AND ID <= 30').set_index('ID')
In [6]:
LandcoverTypes = db.fetch_as_pandas_df(table='LandcoverTypes',
fields=['*']).set_index('ID')
In [7]:
LandcoverArea = db.fetch_as_pandas_df(table='LandcoverAreas',
fields=['*'],
where='IncludedArea = "500m"').set_index('ID')
In [8]:
landcover_area = LandcoverArea.join(Sites.drop('SiteID', axis=1), on='SiteID', how='right').sort_values(by='SiteID')
In [9]:
full_area = 775665.717
sort on landcover percentage
In [10]:
landcover_area_nosort = landcover_area
In [11]:
landcover_area.sort_values(by=['9', '2'],
ascending=[False, True],
inplace=True)
In [12]:
landcover_area['SiteID'].as_matrix()
Out[12]:
In [21]:
# all categories
In [15]:
plt.figure(figsize=(15, 5))
bar_width = 0.9
ID = np.array([ n for n in range(len(landcover_area)) ])
SiteIDs = landcover_area['SiteID'].as_matrix()
left = ID + 0.05
height = np.zeros(len(landcover_area))
bottom = np.zeros(len(landcover_area))
for index, column in landcover_area.ix[:,'1':'15'].iteritems():
height = column.as_matrix()
plt.bar(left=left,
height=height,
bottom=bottom,
width=bar_width,
color=LandcoverTypes['Color'][int(index)],
edgecolor=None,
linewidth=0)
bottom = bottom + height
plt.xlim(0, 30)
plt.ylim(0, full_area)
plt.xlabel('Sites')
plt.ylabel('Area (square meters)')
plt.title('Landcover')
xticks = ID + 0.5
xticklabels = landcover_area['SiteName'].as_matrix()
xticklabels = [ "{0} - {1}".format(xticklabels[i], SiteIDs[i]) for i in ID ]
plt.xticks(xticks, xticklabels, rotation='vertical')
plt.show()
In [23]:
IndexNDSI = db.fetch_as_pandas_df(table='IndexNDSI', fields=['Sound', 'ndsi_left', 'ndsi_right', 'biophony_left', 'biophony_right', 'anthrophony_left', 'anthrophony_right']).set_index('Sound')
In [24]:
ndsi = IndexNDSI.join(Sounds).join(Sites.drop('SiteID', axis=1), on='SiteID')
In [25]:
ndsi_collection1 = ndsi.groupby('ColID').get_group(1)
In [26]:
ndsi_collection1 = ndsi_collection1.rename(columns={"SiteID": "ID"})
In [27]:
ndsi_collection1_byID = ndsi_collection1.groupby('ID')
In [28]:
xticklabels = landcover_area['SiteName'].as_matrix()
xticklabels = [ "{0} - {1}".format(xticklabels[i], SiteIDs[i]) for i in ID ]
In [29]:
plt.figure(figsize=(15,10))
for name, group in ndsi_collection1_byID:
x = (group['ID'].as_matrix() - 100) - 0.1
y = group['biophony_left'].as_matrix()
plt.plot(x, y, 'r-')
plt.scatter(x, y, color='red', marker='.')
x = (group['ID'].as_matrix() - 100) + 0.1
y = group['biophony_right'].as_matrix()
plt.plot(x, y, 'b-')
plt.scatter(x, y, color='blue', marker='.')
plt.xlim(0, 31)
plt.ylim(0, 2.5)
plt.xlabel('Sites')
plt.ylabel('biophony')
plt.title('biophony_left and biophony_right')
xticks = [i for i in range(1, len(ndsi_collection1_byID)+1)]
xticklabels = Sites.sort_index()['SiteName'].as_matrix()
xticklabels = ["{0} - {1}".format(xticklabels[i-1], i) for i in xticks]
plt.xticks(xticks, xticklabels, rotation='vertical')
plt.grid()